import java.util.*;
import java.io.*;

public class Admin {
	HashMap<Integer, Station> stationGraph;
	HashMap<Integer, Train> trainGraph;
	HashMap<Integer, Track> trackGraph;
	BufferedReader input;

	public Admin() throws Exception {
		stationGraph = new HashMap<Integer, Station>();
		trainGraph = new HashMap<Integer, Train>();
		trackGraph = new HashMap<Integer, Track>();
		input = new BufferedReader(new FileReader("/home/dhiraj/Desktop/input"));
		/* input = new BufferedReader(new InputStreamReader(System.in)); */
	}

	public HashMap<Integer, Station> getStationGraph() {
		return stationGraph;
	}

	public void setStationGraph(HashMap<Integer, Station> stationGraph) {
		this.stationGraph = stationGraph;
	}

	/* To create station objects */
	public void addStation(HashMap<Integer, Station> stationGraph)
			throws IOException {
		try {
			Station station = new Station();

			System.out
					.println("Enter the station name,station code and list of adjacent stations' codes");
			station.setStationName(input.readLine());
			station.setStationCode(Integer.parseInt(input.readLine()));

			/* Inputting the text for list of adjacent stations */
			String text = input.readLine();
			/* Splitting the Adjacent Stations */
			String token[] = text.split(" ");
			/* Getting a reference array list */
			ArrayList<Integer> arraylist = station.getAdjacentStations();
			/* Adding elements to the Array list */
			for (String str : token) {
				arraylist.add(Integer.parseInt(str));
			}
			station.setAdjacentStations(arraylist);
			/* Making the StationGraph */
			this.stationGraph.put(station.getStationCode(), station);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void addTrain(HashMap<Integer, Train> trainGraph) throws Exception {
		/* Creating object of train */
		try {
			Train train = new Train();
			System.out
					.println("Enter Train Name,Source and Destination Code and TrainCode and Inbetween stations");
			/* Inputting the Source destination train_name and train code */
			train.setTrainName(input.readLine());
			train.setSourceStation(Integer.parseInt(input.readLine()));
			train.setDestinationStation(Integer.parseInt(input.readLine()));
			train.setTrainCode(Integer.parseInt(input.readLine()));

			/* Input the text for In between stations */
			String text = input.readLine();
			/* Splitting the Adjacent Stations */
			String token[] = text.split(" ");
			/* A reference of Array list is made so that trains can be stored */
			ArrayList<Integer> arraylist = train.getInBetweenStations();
			/* Adding the trains based on using space as delimiter */
			for (String str : token) {
				arraylist.add(Integer.parseInt(str));
			}
			/* Set the intermediate stations */
			train.setInBetweenStations(arraylist);
			/* Make the trainGraph */
			this.trainGraph.put(train.getTrainCode(), train);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void addTrack(HashMap<Integer, Track> trackGraph) throws Exception {
		try {
			/* Creating object of track */
			Track track = new Track();
			System.out
					.println("Enter next station previous station and trackcode");
			/* Inputting the next station previous station and track code */
			track.setNextStation(Integer.parseInt(input.readLine()));
			track.setPrevStation(Integer.parseInt(input.readLine()));
			track.setTrackCode(Integer.parseInt(input.readLine()));

			/* Make the trainGraph */
			this.trackGraph.put(track.getTrackCode(), track);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void main(String args[]) throws Exception {
		try {
			Admin admin = new Admin();

			System.out
					.println("Enter your choice\n0-Exit\n1-Add Station\n2-Add Train\n3-Add Track\n");
			int choice = Integer.parseInt(admin.input.readLine());

			while (choice != 0) {
				switch (choice) {
				case 1:
					admin.addStation(admin.getStationGraph());
					for (Integer var : admin.getStationGraph().keySet()) {
						System.out.println(admin.getStationGraph().get(var)
								.getStationCode()
								+ ": "
								+ admin.getStationGraph().get(var)
										.getStationName());
					}
					break;
				case 2:
					admin.addTrain(admin.getTrainGraph());
					for (Integer var : admin.getTrainGraph().keySet()) {
						System.out
								.println(admin.getTrainGraph().get(var)
										.getTrainCode()
										+ ": "
										+ admin.getTrainGraph().get(var)
												.getTrainName());
					}
					break;
				case 3:
					admin.addTrack(admin.getTrackGraph());
					for (Integer var : admin.getTrackGraph().keySet()) {
						System.out.println(admin.getTrackGraph().get(var)
								.getTrackCode()
								+ ": "
								+ admin.getTrackGraph().get(var)
										.getNextStation()
								+ " "
								+ admin.getTrackGraph().get(var)
										.getPrevStation());
					}
					break;
				default:
					break;
				}
				System.out
						.println("Enter your choice\n0-Exit\n1-Add Station\n2-Add Train\n3-Add Track\n");
				choice = Integer.parseInt(admin.input.readLine());
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public HashMap<Integer, Train> getTrainGraph() {
		return trainGraph;
	}

	public void setTrainGraph(HashMap<Integer, Train> trainGraph) {
		this.trainGraph = trainGraph;
	}

	public HashMap<Integer, Track> getTrackGraph() {
		return trackGraph;
	}

	public void setTrackGraph(HashMap<Integer, Track> trackGraph) {
		this.trackGraph = trackGraph;
	}

}
